package com.example.aopproject;

import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getSimpleName();
    private static final long DELAY_TIME = 3000L;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        initView();
    }

    private void initView() {
        Button btnStep1 = (Button) findViewById(R.id.main_step_1_btn);
        Button btnStep2 = (Button) findViewById(R.id.main_step_2_btn);
        Button btnStep3 = (Button) findViewById(R.id.main_step_3_btn);

        btnStep1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sayHello();
            }
        });

        btnStep2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                greet();
            }
        });

        btnStep3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sayGoodbye();
            }
        });
    }

    @BehaviorAnn(value = Constant.AOP_VALUE.SAY_GOODBYE_VALUE, level = 1)
    public void sayGoodbye() {
        SystemClock.sleep(DELAY_TIME);
        Log.d(TAG, getString(R.string.say_goodbye_content));
    }

    @BehaviorAnn(value = Constant.AOP_VALUE.GREET_VALUE, level = 2)
    private void greet() {
        SystemClock.sleep(DELAY_TIME);
        Log.d(TAG, getString(R.string.greet_content));
    }

    @BehaviorAnn(value = Constant.AOP_VALUE.SAY_HELLO_VALUE, level = 3)
    private String sayHello() {
        SystemClock.sleep(DELAY_TIME);
        Log.d(TAG, getString(R.string.sayHello_content));
        return getString(R.string.sayHello_result_content);
    }
}
